#pragma once

#include <string>
#include <vector>
#include "DetourNavMeshQuery.h"
#include "DetourCommon.h"
#include "DetourNavMesh.h"
#include "platform.h"
#include "NavMeshPoint.h"

const long RCN_NAVMESH_VERSION = 1;
const int Max_Path_Size = 256;
const int Max_Straight_Path_Size = 256;

class NavMesh
{
public:
	NavMesh();
	virtual ~NavMesh();

	bool Create(uint8* data, size_t flen, int maxNodes, float extents[3], float wideExtents[3]);
	bool Create(std::string path, int maxNodes, float extents[3], float wideExtents[3]);
	int FindStraightPath(const float* startPoint, const float* endPoint, Vector3 straightPathPoints[]);
	bool GetPolyHeight(float x, float y, float z, float* height);
	bool FindNearestPoly(float x, float y, float z, bool useWideExtents, float* resultPoint);
	bool Raycast(float x1, float y1, float z1, float x2, float y2, float z2);
	bool MoveAlongSurface(float x1, float y1, float z1, float x2, float y2, float z2, float resultPoint[3]);

private:
	bool GetNavMeshPoint(float x, float y, float z, float extents[3], NavMeshPoint* navMeshPoint);
	bool GetNavMeshPoint(float x, float y, float z, NavMeshPoint* navMeshPoint);

	dtNavMesh* mNavMeshPointer;
	dtNavMeshQuery* mNavMeshQueryPointer;
	dtQueryFilter* mQueryFilterPointer;
	float mExtents[3];
	float mWideExtents[3];
	dtPolyRef mPathPolyBuffer[Max_Path_Size];
	float mStraightPathBuffer[Max_Path_Size * 3];
	unsigned char mStraightPathFlagBuffer[Max_Path_Size];
	dtPolyRef mStraightPathPolyBuffer[Max_Path_Size];
	Vector3 mStraightPathPointBuffer[Max_Straight_Path_Size];
	dtPolyRef mRaycastPathPolyBuffer[Max_Path_Size];
	int mRaycastPathCount;
	dtPolyRef mVisitedPolyBuffer[Max_Path_Size];
	int mVisitedCount;
};

